
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../im/page/bloc/DraggableBloc.dart';
import '../../im/page/view/DraggableFloatingView.dart';
import '../../im/util/DialogUtil.dart';

class OverlayDemo extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Overlay Example')),
      body: Column(
        children: [
          ElevatedButton(
            onPressed: () => showOverlay1(context),
            child: Text('Show Overlay'),
          ),
          SizedBox(height: 20,),
          ElevatedButton(
            onPressed: () => showOverlay2(context),
            child: Text('Show Overlay2'),
          )
        ],
      ),
    );
  }

  showOverlay1(BuildContext context) {
    final overlayEntry = createOverlayEntry(context);
    Overlay.of(context).insert(overlayEntry);
  }

  showOverlay2(BuildContext context) {
    overlay(context);
  }

  OverlayEntry createOverlayEntry(BuildContext context) {
    return OverlayEntry(
      builder: (context) => DraggableFloatingView(child: Material(
        elevation: 4.0,
        borderRadius: BorderRadius.all(Radius.circular(10)),
        child: Container(
          width: 200,
          height: 100,
          padding: EdgeInsets.all(16.0),
          color: Colors.white,
          child: Text('11111111111111111111'),
        ),
      ),),
    );
  }

  void overlay(BuildContext context) {
    var child = DraggableFloatingView(child: Material(
      elevation: 4.0,
      borderRadius: BorderRadius.all(Radius.circular(10)),
      child: Container(
        width: 200,
        height: 100,
        padding: EdgeInsets.all(16.0),
        color: Colors.white,
        child: Text('11111111111111111111'),
      ),
    ),);
    showOverlay(context, child);
  }

}